<template>
  <div class="box">
    <div class="search">
      <Search-view @child-event="handChildData" @child-reset="resetFun">
        <template #title> 标签名称 </template>
      </Search-view>
    </div>
    <div class="mian">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="分类名称" width="300">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" width="300">
          <template slot-scope="scope">
            <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="list.total"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import SearchView from "../../components/SearchView.vue";
import { TagList } from "../../units/api.js";
import { TagDel } from "../../units/api.js";
export default {
  data() {
    return {
      list: {
        current: 1,
        size: 10,
        tagName: "",
      },
      tableData: [],
    };
  },
  components: {
    SearchView,
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
      let res = await TagList(this.list);
      console.log(res);
      this.tableData = res.data.data.records;
      this.list = res.data.data;
    },
    // 删除
    handleDelete(index, row) {
      console.log(index, row);
      this.list.tagId = row.id;
      // TagDel
      this.list.categoryId = row.id;
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          let res = await TagDel(this.list);
          console.log(res);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.getList();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 搜索
    handChildData(input, dateStart, dateEnd) {
      this.list.tagName = input;
      if (dateStart) {
        this.list.startDate = dateStart.toLocaleString().replace(/[/]/g,"-");
        this.list.endDate = dateEnd.toLocaleString().replace(/[/]/g,"-");
      }
      console.log(
        "赋值后的数据",
        this.list.tagName,
        this.list.startDate,
        this.list.endDate
      );
      this.getList();
    },
    //重置
    resetFun() {},
    //翻页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.list.current = val;
      this.getList();
    },
  },
};
</script>

<style>
</style>